import * as THREE from 'three'
import { GLTF, GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";

export default class AssestManager {
    private assests: string[];
    private gLTFLoader = new GLTFLoader();
    constructor(assests: string[]) {
        this.assests = assests;
    }

    public async load(onProgress: Function) {
        const map: { [key: string]: GLTF } = {};
        for (let i = 0; i < this.assests.length; i++) {
            const assest = this.assests[i];
            const gltf = await this.gLTFLoader.loadAsync(assest);
            const key = assest.split('/').pop() as string;
            map[key] = gltf;
            onProgress(i / (this.assests.length - 1));
        }
        return map;
    }
}